<?php
// 修改商铺信息
require $this->website['path']['action'] . '/admin/isedit.php';

$json = array('status' => 'error', 'msg' => '', 'data' => []);

$data = fn_post('data');

$data = json_decode($data, 1);
//data['shops']
//data['postage']
//data['check']

$id = $data['shops']['id'] ?? false;
unset($data['shops']['id']);

if (!$id) {
	$json['msg'] = '错误的商铺ID' . $data['shops']['id'];
} elseif (!$this->website['class']['db']
		->table('shops')
		->where('id=?', $id)
		->limit(1)
		->count()) {
	$json['msg'] = '未找到商铺或已被删除';
} else {

	if (count($data['shops'])) {
		$field = array_keys($data['shops']);
		$value = array_values($data['shops']);
		$field[] = 'createtime';
		$value[] = $_SERVER['REQUEST_TIME'];
		$this->website['class']['db']
				->table('shops')
				->field($field)
				->value($value)
				->where('id=?', $id)
				->limit(1)
				->update();
	}

	$json['status'] = 'ok';
	$json['msg'] = '修改商铺成功';
}

$this->json_encode($json);
